package com.myschool.server.dao.support;

import java.util.List;

public interface GenericDao<T> {

	/**
	 * Generic method used to get all objects of a particular type. This is the
	 * same as lookup up all rows in a table.
	 * 
	 * @return list of populated objects
	 */
	List<T> getAll();

	/**
	 * Generic method to save an object - handles both update and insert.
	 * 
	 * @param object the object to save
	 * @return the persisted object
	 */
	T save(final T object);

	/**
	 * Generic method to delete an object based on class and id.
	 * 
	 * @param object the object to remove
	 */
	void remove(final T object);

	/**
	 * Generic method to delete an entry based on an id.
	 *
	 * @param id the primary key of the object to delete
	 * @return the object which has been removed
	 */
	T remove(final Long id);

	/**
	 * Generic method to get an object based on class and identifier. An
	 * ObjectRetrievalFailureException Runtime Exception is thrown if nothing is
	 * found.
	 *
	 * @param id the identifier (primary key) of the object to get
	 * @return a populated object
	 * @see org.springframework.orm.ObjectRetrievalFailureException
	 */
	T get(final Long id);

	/** Exposing flush for circumstances where it is deemed efficient.
	Do not use without measuring the impact - it will flush any changes in Hibernate to the database and will slow
	things down if over-used.
	*/
	void flush();

	/**
	 * Checks for existence of an object of type T using the id arg.
	 *
	 * @param id the id of the entity
	 * @return <b>true</b> if it exists, <b>false</b> if it doesn't
	 */
	boolean exists(final Long id);

}
